#include<bits/stdc++.h>
using namespace std;
int n;
map<string,int> S;
bool judge(string ad)
{
	int a=0,b=0;
	for(int i=0;i<ad.size();i++)
		a+=(ad[i]=='.'),b+=(ad[i]==':');
	if(a!=3 || b!=1) return 0;
	int i=0,j=0;
	for(int temp=1;temp<=3;temp++){
		int num=0;
		for(;j<=ad.size();j++){
			if(ad[j]<'0' || ad[j]>'9') break;
			num=num*10+ad[j]-'0';
		}
		if((j-i>1 && ad[i]=='0') || ad[j]!='.' || num>255) return 0;
		j++;
		i=j;
	}
	int num=0;
	for(;j<=ad.size();j++){
		if(ad[j]<'0' || ad[j]>'9') break;
		num=num*10+ad[j]-'0';
	}
	if((j-i>1 && ad[i]=='0') || ad[j]!=':' || num>255) return 0;
	num=0;
	j++;
	i=j;
	for(;j<=ad.size();j++){
		if(ad[j]<'0' || ad[j]>'9') break;
		num=num*10+ad[j]-'0';
	}
	if((j-i>1 && ad[i]=='0')  || num>65535) return 0;
	return 1;
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		string op,ad;
		cin>>op>>ad;
		if(judge(ad)==0) cout<<"ERR";
		else if(op=="Server"){
			if(S[ad]!=0) cout<<"FAIL";
			else S[ad]=i,cout<<"OK";
		}
		else {
			if(S[ad]==0) cout<<"FAIL";
			else cout<<S[ad];
		}
		cout<<'\n';
	}
	return 0;
}

